package com.zx.idc.backend.gui.report.roperationlog;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zx.idc.backend.gui.common.BaseApi;
import com.zx.idc.backend.gui.common.Result;
import com.zx.idc.backend.gui.report.common.BaseDayApi;
import com.zx.idc.ds.report.roperationlog.entity.ROperationLogDay;
import com.zx.idc.ds.report.roperationlog.service.IROperationLogDayService;
import com.zx.idc.ds.report.roperationlog.vo.ROperationLogDayVo;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.joor.Reflect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * <p>
 * 操作日志统计表-日报 前端控制器
 * </p>
 *
 * @author rxliuli
 * @since 2019-01-31
 */
@RestController
@RequestMapping("/api/rOperationLogDay")
public class ROperationLogDayController extends BaseApi implements BaseDayApi<IROperationLogDayService, ROperationLogDay, ROperationLogDayVo> {
    @Autowired
    private IROperationLogDayService irOperationLogDayService;

    @GetMapping("/report")
    @RequiresPermissions(value = {"report-statistics:r-domain-archive", "report-statistics:r-illegal-info", "report-statistics:r-illegal-media", "report-statistics:r-shield", "report-statistics:t-log-security", "report-statistics:t-log-operation"}, logical = Logical.OR)
    public Result<List<ROperationLogDay>> report(ROperationLogDayVo vo) {
        final LocalDate dateNow = Reflect.on(vo).get("dateNow");
        return success(irOperationLogDayService.selectList(
            new EntityWrapper<ROperationLogDay>()
                .eq("belongMonth", dateNow.format(DateTimeFormatter.ofPattern("yyyy-MM")))
                .le("day", dateNow.getDayOfMonth())
            )
        );
    }
}

